import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker
from f import offline_rate
from datetime import datetime

# x = [
# 	['益阳', '益阳普适型地灾监测预警项目', '385', '353', '32', '91.69'],
# 	['湘西', '湘西州地质灾害隐患普适监测项目', '295', '288', '7', '97.63'],
# 	['长沙', '长沙市普适型地质灾害监测项目', '110', '107', '3', '97.27'],
# 	['邵阳', '邵阳市普适型地灾监测预警项目', '329', '307', '22', '93.31'],
# 	['张家界', '张家界市普适型地灾监测预警项目（2021年第二批）', '436', '429', '7', '98.39'],
# 	['株洲', '株洲市普适型监测项目', '195', '173', '22', '88.72'],
# 	['常德', '常德普适型测试项目', '495', '471', '24', '95.15'],
# 	['娄底', '娄底市普适化地灾监测项目', '85', '78', '7', '91.76']
# ]

x = offline_rate()
print('x',x)

offline = []
online = []
total = []
name = []
for item in x:
    name.append(item[0])
    total.append(item[2])
    offline.append(item[-2])
    online.append(item[-1])

def stat():
    c = (
        Line()
        .add_xaxis(name)
        .add_yaxis("设备在线率(%省略)", online, is_smooth=True)
        .add_yaxis("设备总数", total, is_smooth=True)
        .add_yaxis("掉线设备", offline, is_smooth=True)
        .set_global_opts(title_opts=opts.TitleOpts(title="1170项目云平台设备在线率"))
    )
    c.render("line1_smooth.html")

stat()